package sg.nus.iss.vmcs.gui.elements;

import java.awt.Color;

/**
 * Abstract Class and Factory for Colored Display States
 * @author Philip Chew
 */
public abstract class VariableDisplayState {
	/**
	 * Enumeration for the various Variable Display State Types.
	 * Used for retrieval in the factory method
	 * @author Philip Chew
	 */
	public enum Type {
		PwdOnState, PwdOffState, WarningOn, WarningOff, Editable, UnEditable, ClearOn, ClearOff,
		BIOnState, BIOffState
	}
	
	/**
	 * Abstract method that sets the display component
	 * @param vdsc Variable Display Context
	 */
	public abstract void setDisplayComponent(VariableDisplayStateContext vdsc);
	
	/**
	 * Gets a variable display state
	 */
	public static VariableDisplayState getDisplayState(Type wdst) {
		
		switch(wdst) {
			case PwdOnState:
				return new PwdOnState();
			case PwdOffState:
				return new PwdOffState();
			case WarningOn:
				return new WarningOn();
			case WarningOff:
				return new WarningOff();
			case Editable:
				return new Editable();
			case UnEditable:
				return new Uneditable();
			case ClearOn:
				return new ClearOn();
			case ClearOff:
				return new ClearOff();
			case BIOnState:
				return new BIOnState();
			case BIOffState:
				return new BIOffState();
			default:
				return null;
		}
	}
		
	private static class PwdOnState extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.yellow);
			vdsc.getDisplayComponent().setBackground(Color.red);
			vdsc.setVariableDisplayState(new PwdOffState());
		}
	}
	
	private static class PwdOffState extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.white);
			vdsc.getDisplayComponent().setBackground(Color.black);
			vdsc.setVariableDisplayState(new PwdOnState());
		}
	}
	
	private static class Editable extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.black);
			vdsc.getDisplayComponent().setBackground(Color.white);
			vdsc.setVariableDisplayState(new Uneditable());
		}
	}
	
	private static class Uneditable extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.white);
			vdsc.getDisplayComponent().setBackground(Color.blue);
			vdsc.setVariableDisplayState(new Editable());
		}
	}
	
	private static class WarningOn extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.white);
			vdsc.getDisplayComponent().setBackground(Color.red);
			vdsc.setVariableDisplayState(new WarningOff());
		}
	}
	
	private static class WarningOff extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.gray);
			vdsc.getDisplayComponent().setBackground(Color.red);
			vdsc.setVariableDisplayState(new WarningOn());
		}
	}
	
	private static class ClearOn extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.white);
			vdsc.getDisplayComponent().setBackground(Color.green);
			vdsc.setVariableDisplayState(new ClearOff());
		}
	}
	
	private static class ClearOff extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.gray);
			vdsc.getDisplayComponent().setBackground(Color.green);
			vdsc.setVariableDisplayState(new ClearOn());
		}
	}
	
	private static class BIOnState extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.black);
			vdsc.getDisplayComponent().setBackground(Color.white);
			vdsc.setVariableDisplayState(new BIOffState());
		}
	}
	
	private static class BIOffState extends VariableDisplayState {
		@Override
		public void setDisplayComponent(VariableDisplayStateContext vdsc) {
			vdsc.getDisplayComponent().setForeground(Color.black);
			vdsc.getDisplayComponent().setBackground(Color.black);
			vdsc.setVariableDisplayState(new BIOnState());
		}
	}
}
